<?php
ob_start();
include_once "../connect.php";
session_start();
$id_member = $_SESSION["id_member"];

// รับค่ามาเก็บไว้ใน 
$mtn_id = $_POST["mtn_id"];
$chkCanSV = $_POST["chkCanSV"];
$chkChgDev = $_POST["chkChgDev"];
$chkNotChgDev = $_POST["chkNotChgDev"];
$chkNewProgram = $_POST["chkNewProgram"];
$chkEditProgram = $_POST["chkEditProgram"];
$txtmainten = $_POST["txtmainten"];
$alt_Id = $_POST["alt_Id"];
//$id_member = $_POST["id_member"];
$emp_id = $_POST["emp_id"];
//$txtdateMainten = $_POST["datepicker"];
$datetime = $_POST["datetime"];
$time = $_POST["datetime"];
$mydatetime=date('Y-m-d', strtotime($datetime));
$mytime = date('H:i:s', strtotime($time));
$altStatus = $_POST["opStatus"];

if (!empty($alt_Id)) {
    $sqlalt = "UPDATE `db_itmanager`.`altcomservice` SET
   `id_member` = '$id_member' 
WHERE `altcomservice`.`alt_Id` = '$alt_Id' ";
    mysql_query($sqlalt);
} else {

    header("location:listCom.php");
}

if (empty($mtn_id)) {
   
$sql = "INSERT INTO `db_itmanager`.`mtncomservice` (
`mtn_can` ,
`mtn_chgDevice` ,
`mtn_notDevice` ,
`mtn_newProgram` ,
`mtn_editProgram` ,
`mtn_detail` ,
`mtn_date` ,
`mtn_time` ,
`alt_Id` ,
`id_member` ,
`emp_id` 
)
VALUES (
'$chkCanSV', '$chkChgDev', '$chkNotChgDev', '$chkNewProgram', '$chkEditProgram','$txtmainten', '$mydatetime' , '$mytime',  '$alt_Id', '$id_member' ,'$emp_id'
)";
mysql_query($sql);

$sqlalt = "UPDATE  `db_itmanager`.`altcomservice` 
        SET  `alt_status` =  '$altStatus' 
            WHERE  `altcomservice`.`alt_Id` = '$alt_Id'";
    mysql_query($sqlalt);
} else {
 $sqlUpdate = "UPDATE `db_itmanager`.`mtncomservice` SET 
`mtn_can` = '$chkCanSV',
`mtn_chgDevice` = '$chkChgDev',
`mtn_notDevice` = '$chkNotChgDev',
`mtn_newProgram` = '$chkNewProgram',
`mtn_editProgram` = '$chkEditProgram' ,
`mtn_detail` = '$txtmainten' ,
`mtn_date` = '$mydatetime' ,
`mtn_time` = '$mytime'
WHERE `mtncomservice`.`mtn_id` = '$mtn_id' " ;
 mysql_query($sqlUpdate);
}
if (mysql_query) {
  header("location:altServiceComUp.php?alt_Id=$alt_Id");
  //    header("location:listCom.php");
//    echo "<script language='javascript'>
//			   alert('Complete');
//			   setTimeout(\"parent.$.fancybox.close()\",1000); 
//			  </script>";
//    echo "<meta http-equiv='refresh' content='5; url=listCom.php'>";
} else {
    echo mysql_error();
}
?>
